package mx.com.crowdgine.camera;

import javax.media.opengl.GL2;

import mx.com.crowdgine.util.math.Vector3f;

public class ScriptedCamera extends GeneralCamera{

	private float movementSpeed = 0.8f; // move 10 units per second
	boolean incrementPitch = true;
	boolean incrementYaw = true;
	private float time = 0;
	
	public void interact(GL2 gl) {
		if(time%3000 < 10){
			yaw = 0;
			pitch = 0;
			incrementPitch = true;
			incrementYaw = true;
			this.setPosition(new Vector3f(320, -100, 240));
		}else if(time%3000 >= 10 && time%3000 < 500){
			if(incrementYaw)
				yaw += 0.4;
			else
				yaw -= 0.4;
			
			if(yaw > 90)
				incrementYaw = false;
			if(yaw < -90)
				incrementYaw = true;
		}else if(time%3000 >= 500 && time%3000 < 750){
			yaw = 0;
			pitch = -10;
			this.setPosition(new Vector3f(320, -20, 240));
		}else if(time%3000 >= 750 && time%3000 < 760){
			yaw = 0;
			pitch = 0;
			incrementPitch = true;
			incrementYaw = true;
			this.setPosition(new Vector3f(320, -200, 240));
		}else{
			walkForward(1.5f);
			yaw += 0.4;
			if(incrementPitch)
				pitch += 0.1;
			else
				pitch -= 0.1;
			if(pitch > 30)
				incrementPitch = false;
			if(pitch < -15)
				incrementPitch = true;
		}
		super.interact(gl);
	}
	
	public void walkForward(float distance) {
		position.setX(position.getX() + (distance * movementSpeed)
				* (float) Math.sin(Math.toRadians(yaw)));
		position.setZ(position.getZ() - (distance * movementSpeed)
				* (float) Math.cos(Math.toRadians(yaw)));
	}
	
	public void setTime(float time){
		this.time = time;
	}
}
